<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="./xsltdoc.xsl" type="text/xsl" media="screen"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2004/10/xpath-functions" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:owl="http://www.w3.org/2002/07/owl#">
	<xsl:output media-type="text/xml" version="1.0" encoding="UTF-8" indent="yes" use-character-maps="owl"/>
	<xsl:strip-space elements="*"/>
	<xsl:character-map name="owl">
		<xsl:output-character character="&#932;" string="&amp;"/>
	</xsl:character-map>
	
	<xsl:template match="/">
		<!-- Generate entity definitions for each ClassificationScheme -->
		<xsl:text disable-output-escaping="yes">&#10;&lt;!DOCTYPE rdf:RDF [&#10;</xsl:text>
		<xsl:for-each select="//ClassificationScheme">
			<xsl:text disable-output-escaping="yes">&#09;&lt;!ENTITY </xsl:text>
			<xsl:value-of select="@id"/>
			<xsl:text disable-output-escaping="yes"> 'urn:</xsl:text>
			<xsl:value-of select="@uri"/>
			<xsl:text disable-output-escaping="yes">#</xsl:text>
			<xsl:text disable-output-escaping="yes">'&gt;&#10;</xsl:text>
		</xsl:for-each>
		<xsl:text disable-output-escaping="yes">]&gt;&#10;</xsl:text>	
		<rdf:RDF>
			<owl:Ontology rdf:about="">
				<rdfs:comment>OWL ontology generated by the cs2owl XML Style Sheet (http://rhizomik.net/redefer)</rdfs:comment>
			</owl:Ontology>
			<xsl:apply-templates/>
		</rdf:RDF>
	</xsl:template>
	
	<xsl:template match="ClassificationScheme">
		<xsl:variable name="schemeEntity">
			<xsl:value-of select="concat(concat('&#932;',@id),';')"/>
		</xsl:variable>
		<xsl:apply-templates>
			<xsl:with-param name="uri" select="$schemeEntity"/>
		</xsl:apply-templates>
	</xsl:template> 
	
	<xsl:template match="Term">
		<xsl:param name="uri"/>
		<xsl:param name="parentID"/>
		<xsl:variable name="termID">
			<xsl:if test="$concat">
				<xsl:value-of select="$parentID"/>
				<xsl:if test="parent::Term">:</xsl:if>
			</xsl:if>
			<xsl:value-of select="replace(@termID,' ','%20')"/>
		</xsl:variable>
		<owl:Class rdf:about="{concat($uri,$termID)}">
			<xsl:for-each select="Name">
				<rdfs:label>
					<xsl:if test="@xml:lang">
						<xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
					</xsl:if>
					<xsl:value-of select="."/>
				</rdfs:label>
			</xsl:for-each>
			<xsl:for-each select="Definition">
				<rdfs:comment>
					<xsl:if test="@xml:lang">
						<xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
					</xsl:if>
					<xsl:value-of select="."/>
				</rdfs:comment>
			</xsl:for-each>
			<xsl:if test="parent::Term">
				<rdfs:subClassOf rdf:resource="{concat($uri,escape-uri($parentID,false()))}"/>
			</xsl:if>
		</owl:Class>
		<xsl:apply-templates select="child::Term">
			<xsl:with-param name="uri" select="$uri"/>
			<xsl:with-param name="parentID" select="$termID"/>
		</xsl:apply-templates>
	</xsl:template>
	
</xsl:stylesheet>

